package com.sumainfor.pc.gmio.service.impl;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.gmio.dao.SeBillParticularMapper;
import com.sumainfor.pc.gmio.dao.SeEleMeterMapper;
import com.sumainfor.pc.gmio.dao.SeGasMeterMapper;
import com.sumainfor.pc.gmio.dao.SeWaterMeterMapper;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.gmio.service.SeBillParticularService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 */
@Service
public class SeBillParticularSerivceImpl implements SeBillParticularService {

    private ReentrantLock lock = new ReentrantLock(false);
    Logger log= LoggerFactory.getLogger(SeBillParticularSerivceImpl.class);
    @Autowired
    private SeEleMeterMapper seEleMeterMapper;
    @Autowired
    private SeWaterMeterMapper seWaterMeterMapper;
    @Autowired
    private SeGasMeterMapper seGasMeterMapper;
    @Autowired
    private SeBillParticularMapper seBillParticularMapper;
    @Autowired
    private ZpcMktFeign zpcMktFeign;
    /**
     * 查询电表录入记录的列表
     * @param params
     * @return
     */
    public JsonResult getBillParticular(Map<String,Object>params, Pager pager) {
        //查询水电燃表的房源编号
        List<Map<String,Object>> ewgList=seBillParticularMapper.getEwgList(params);
        PageUtils pageUtils = new PageUtils();
        if (params.get("IfMarket").equals("1")) {
            if(ewgList.size()<=0){
                //return null;
              //再次修改
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(),params,0);
            }
            params.put("ewgList",ewgList);
            System.out.println("传递到市场部的参数:"+params);
            JsonResult result = zpcMktFeign.getHouInfoListForBillParticular(params);
           /* System.out.println("市场部返回的值:"+result);
            JsonResult gmiolist=new JsonResult();//保存比对成功的list集合
            List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
            Map<String,Object>map=(Map<String,Object>)result.get("result");
            //市场部的房源列表
            List<Map<String,Object>> mktlist=(List<Map<String,Object>>)map.get("dataList");
            int count=0;//记录比对成功的数量
            for (Map<String,Object> mktmap : mktlist){
                System.out.println("mktmap:"+mktmap);
                mktmap.putAll(params);
                boolean biaoshi=false;
                Map<String,Object> mapw=seWaterMeterMapper.getWaterMeterByHouInfoId(mktmap);
                if (mapw!=null){
                    mktmap.put("BillMoneyw",mapw.get("BillMoney"));
                    biaoshi=true;
                }else{
                    mktmap.put("BillMoneyw","");
                }
                Map<String,Object> mape=seEleMeterMapper.getEleMeterByHouInfoId(mktmap);
                if (mape!=null){
                    mktmap.put("BillMoneye",mape.get("BillMoney"));
                    biaoshi=true;
                }else{
                    mktmap.put("BillMoneye","");
                }
                Map<String,Object> mapg=seGasMeterMapper.getGasMeterByHouInfoId(mktmap);
                if (mapg!=null){
                    mktmap.put("BillMoneyg",mapg.get("BillMoney"));
                    biaoshi=true;
                }else{
                    mktmap.put("BillMoneyg","");
                }
                if (biaoshi){
                    list.add(mktmap);
                    count++;
                }
                System.out.println("list:"+list);
            }
            map.put("dataList",list);
            map.put("totalCount",count);
            gmiolist.put("errorCode",'0');
            gmiolist.put("result",map);*/
            return result;
        }else{//只有市场部条件和没有任何条件
            if(ewgList.size()<=0){
                //return null;
                //zc修改
                return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(),params,0);
            }
            params.put("ewgList",ewgList);
            System.out.println("传递到市场部的参数:"+params);
            System.out.println("传递到市场部的参数:"+pager);
            JsonResult result = zpcMktFeign.getHouInfoListForBillParticular(params);
            Map<String,Object>map=(Map<String,Object>)result.get("result");
            //市场部的房源列表
            List<Map<String,Object>> mktlist=(List<Map<String,Object>>)map.get("dataList");
   /*         for (Map<String,Object> mktmap : mktlist){
                Map<String,Object> mapw=seWaterMeterMapper.getWaterMeterByHouInfoId(mktmap);
                if (mapw!=null){
                    mktmap.put("BillMoneyw",mapw.get("BillMoney"));
                }else{
                    mktmap.put("BillMoneyw","");
                }
                Map<String,Object> mape=seEleMeterMapper.getEleMeterByHouInfoId(mktmap);
                if (mape!=null){
                    mktmap.put("BillMoneye",mape.get("BillMoney"));
                }else{
                    mktmap.put("BillMoneye","");
                }
                Map<String,Object> mapg=seGasMeterMapper.getGasMeterByHouInfoId(mktmap);
                if (mapg!=null){
                    mktmap.put("BillMoneyg",mapg.get("BillMoney"));
                }else{
                    mktmap.put("BillMoneyg","");
                }
            }*/
            return result;
        }
    }
}
